package cc.shacocloud.luanniao.core.service.oss.local

import cc.shacocloud.luanniao.core.service.oss.AbstractObjectStorageService
import java.io.File
import java.io.InputStream

/**
 * 本地文件存储服务实现
 *
 * @author 思追(shaco)
 */
class LocalObjectStorageServiceImpl(

    /**
     * 基础存储的文件目录
     */
    val properties: LocalOssProperties,
) : AbstractObjectStorageService() {

    override fun putObject(bucket: String, objectKey: String, inputStream: InputStream, length: Long, partSize: Long?) {
        val outputFile = File(properties.baseDir, destPath(bucket, objectKey))
        outputFile.outputStream().use { inputStream.transferTo(it) }
    }

    override fun existObject(bucket: String, objectKey: String): Boolean {
        val outputFile = File(properties.baseDir, destPath(bucket, objectKey))
        return outputFile.exists()
    }

    override fun getObject(bucket: String, objectKey: String): InputStream {
        val outputFile = File(properties.baseDir, destPath(bucket, objectKey))
        return outputFile.inputStream()
    }
}